import { defineStore } from "pinia";
import { decrypto, encrypto } from "@/utils/crypto";

export const someFieldStore = defineStore("somefield", {
  state: (): any => {
    return {
       order_num: "",
       clientfields:[],
    };
  },
  actions: {
    // 自定义重置方法，保留 company 字段
    $reset() {
      // 保存 company 字段
      const companyField = this.clientfields.find((item: any) => item.key === 'company');
      
      // 重置所有字段
      this.order_num = "";
      this.clientfields = [];
      
      // 如果存在 company 字段，则恢复它
      if (companyField) {
        this.clientfields.push(companyField);
      }
    }
  },
  persist: {
    key: "somefield",
    serializer: {
      deserialize: decrypto,
      serialize: encrypto,
    },
  },
});